package com.my.study.entity.vo;

import com.my.study.enums.BusinessExceptionEnum;
import lombok.Data;

@Data
public class ResponseVO<T> {

    private Integer resultCode;

    private String resultMsg;

    private T data;

    private ResponseVO() {
    }

    public ResponseVO(Integer resultCode, String resultMsg, T data) {
        this.data = data;
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
    }

    public static <T> ResponseVO success(T data) {
        ResponseVO<T> responseVO = new ResponseVO();
        responseVO.setData(data);
        responseVO.setResultCode(Integer.valueOf(BusinessExceptionEnum.SUCCESS.code));
        responseVO.setResultMsg(BusinessExceptionEnum.SUCCESS.msg);
        return responseVO;
    }

    public static ResponseVO success() {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setResultCode(Integer.valueOf(BusinessExceptionEnum.SUCCESS.code));
        responseVO.setResultMsg(BusinessExceptionEnum.SUCCESS.msg);
        return responseVO;
    }

    public static ResponseVO fail(String resultMsg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setResultCode(Integer.valueOf(BusinessExceptionEnum.FAIL.code));
        responseVO.setResultMsg(resultMsg);
        return responseVO;
    }

    public static ResponseVO fail(Integer resultCode, String resultMsg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setResultCode(resultCode);
        responseVO.setResultMsg(resultMsg);
        return responseVO;
    }
}
